home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
superv22.zip
/
DUMB.ASM
next >
Wrap
Assembly Source File
|
1987-02-10
|
7KB
|
329 lines
PAGE ,132 ; (CTRL-OH) IBM PC PRINTER CONDENSED MODE
TITLE DUMB - RUDIMENTARY DUMB TERMINAL PROGRAM USING SUPERCOM
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CSEG,DS:CSEG,SS:CSEG,ES:CSEG ;ALREADY SET BY DOS LOADER
;
; THIS PROGRAM DEMONSTRATES HOW TO USE A FEW OF THE SUPERCOM
; FEATURES FROM ASSEMBLY LANGUAGE. TERMINATE BY PRESSING ^Z
; IT ALSO DEMONSTRATES HOW TO LOAD SUPERCOM FROM WITHIN AN
; APPLICATION AND THEN REMOVE IT AFTERWARD
;
ORG 100H ;SKIP TO END OF THE PSP
ENTPT: JMP START ;COM FILE ENTRY ALWAYS AT 100H
COPY DB 8,8,8,'(C) Copyright 1987 Doctor Debug - All rights reserved',26
PMSG DB 'SUPERCOM not loaded - Postloading...',13,10,'$'
XMSG DB 13,10,'SUPERCOM removed from memory.',13,10,'$'
PROCEED DB 'Proceed...',13,10,'$'
;
; NOTHING FANCY HERE, JUST SET THE LINE PARAMETERS IN THESE LOCATIONS
;
BAUD DW 1200 ;INIT AT 1200 BAUD
PARITY DB 3 ;1=ODD, 2=NONE, 3=EVEN
STOP DB 1
WORDLEN DB 7 ;7 OR 8
ECHO DB 0 ;0 = OFF, 1 = ON
LF DB 0 ;ADD LF IF 1, NO IF 0
POSTLOAD DB 0 ;1 if SUPERCOM Postloaded
;
START PROC NEAR
;
; FIRST INITIALIZE THE PORT
;
STI
MOV BL,0
MOV AX,BAUD ;DETERMINE BAUD RATE
CMP AX,300
JE B300 ;SET UP FOR 300
;
CMP AX,1200
JE B1200 ;SET UP FOR 1200
;
CMP AX,2400
JE B2400 ;SET UP FOT 2400
;
CMP AX,4800
JE B4800 ;SET UP FOR 4800
;
; DEFAULT = 9600
;
B9600: MOV BL,0E0H ;BL MUST HAVE PROPER CODE
JMP I1
;
B4800: MOV BL,0C0H
JMP I1
;
B2400: MOV BL,0AH
JMP I1
;
B1200: MOV BL,80H
JMP I1
;
B300: MOV BL,40H
;
I1: MOV AH,PARITY ;NOW CHECK PARITY
MOV CL,3
SAL AH,CL
OR BL,AH ;SET THOSE BITS
;
MOV AH,STOP ;HANDLE STOP BITS
DEC AH
MOV CL,2
SAL AH,CL
OR BL,AH ;SET STOP BITS
;
MOV AH,WORDLEN ;NOW SET WORD LENGTH
SUB AH,5
OR BL,AH ;SET THESE BITS
;
; LETS SEE OF SUPERCOM IS LOADED
;
MOV AH,0FH ;FUNCTION F = HELLO?
INT 14H
CMP AX,0AAAH ;RIGHT SIGNATURE?
JE GOOD ;YES, CONTINUE
; SUPER not loaded, lets do it ourselves
Mov DX,Offset PMSG
Mov AH,9
Int 21h ;Prints out message
CALL LOAD ;Load supercom
MOV POSTLOAD,1 ;SET FLAG
GOOD:
MOV AL,BL ;LINE PARAMS IN BL
MOV AH,0CH ;FUNCTION C = OPEN PORT
MOV DX,0
INT 14H ;INITS THE COMM PORT
;
;NOW LOOP, SENDING WHAT'S
;PRINTED AND PRINTING WHAT'S
;SENT...
MOV DX, OFFSET PROCEED
MOV AH,9
INT 21H ;PRINT PROCEED MESSAGE
LOOP: MOV AH,8 ;FN 8 (RECEIVE CHAR)
MOV DX,0
INT 14H ;SEE IF CHAR EXISTS
;
CMP AL,0 ;NO CHAR?
JE L1
MOV DL,AL
MOV AH,2
INT 21H ;PRINT CHAR
;
CMP LF,1 ;ADD LFS?
JNE L1
;
CMP AL,0DH ;CR?
JNE L1 ;NO, CONTINUE
;
MOV DL,0AH ;PRINT LF TOO
MOV AH,2
INT 21H
;
L1: MOV AH,1
INT 16H ;CHAR AVAILABLE?
JZ LOOP ;NO, CONTINUE
;
MOV AH,0
INT 16H ;get char into al
CMP AL,26 ;CTRL-Z?
JNE L2 ;no
;
CMP POSTLOAD,1 ;Are we Postloaded?
Jne L5
; We are postloaded, so a Killport is necessary
Mov DX, Offset XMSG
Mov AH,9
Int 21H ;Tell what we are doing
Mov AH,10H ;Killport Fn #
Mov DX,0 ;Port 0
Int 14h ;DO IT
RET ;AND RETURN
L5:
MOV AH,0DH ;CLOSE PORT
MOV DX,0
INT 14H ;DO IT
RET ;EXIT
;
L2: MOV AH,1
MOV DX,0
INT 14H ;SEND CHARACTER
;
CMP ECHO,1 ;ECHO?
JNE LOOP ;NO, LOOP BACK
;
MOV DL,AL
MOV AH,2
INT 21H ;ECHO THE CHARACTER
;
CMP AL,0DH ;IS IT A CARRIAGE RETURN?
JNE LOOP ;NO GO BACK
;
MOV DL,0AH ;YES PRINT LF WITH IT
MOV AH,2
INT 21H
;
JMP LOOP
;
LOAD PROC
JMP GO
;
; This procedure loads Supercom into memory using the DOS EXEC
; function (4BH).
;
ShellData Label Byte
EnvStr DW 0 ;Will contain environ string seg
CLin DD 0 ;Will contain DW ptr to Command line
PFCB1 DD 0 ;DW pointer to unopened FCB
PFCB2 DD 0 ;Ditto
Comm DB ' /I /X',0 ;Command parameters for SUPER
;Change to suit
FCB1 DB 36 dup(0) ;FCB area 1
FCB2 DB 36 Dup(0) ;FCB area 2
Fname db 'SUPER.COM',0 ;SUPER filename - put a drive
;and path in if necessary, otherwise
;SUPER.COM is expected to be in
;the current directory
SS_Save DW 0 ;Storage for SS
SP_Save DW 0 ;Storage for SP
GO:
; 1st we must save all registers, as they won't be kept intact
; by the call
;
Push AX
Push BX
Push CX
Push DX
Push SI
Push DI
Push DS
Push ES
Push BP
;
; In case this is being used in an .EXE file, I will now set
; all the segment registers to point to CS.
;
Mov AX,CS
Mov DS,AX
Mov ES,AX
;
; Just for fun we will create two unopened FCBs for the exec call
;
Mov AX,2901H ;Function 29 = Parse filename
Mov SI, offset Comm ;Address of Command Line
Mov DI, offset FCB1 ;Where we want the FCB put
Int 21H ;Creates the FCB
Mov DI, offset FCB2 ;Where 2nd FCB should go
Int 21h ;Create it
; Now we play "fill in the blanks" with the above ShellData
; parameter block. We must be sure that the correct segments
; and offsets are there
Mov AX,CS ;Current segment value
Mov Word Ptr[Clin+2],AX ;Put it here...
Mov Word Ptr[PFCB1+2],AX ;and here...
Mov Word Ptr[PFCB2+2],AX ;and finally here.
Mov AX, Offset FCB1 ;Address of FCB we just made
Mov Word Ptr[PFCB1],AX ;Placed into parameter block
Mov AX, Offset FCB2 ;Address of other FCB
Mov Word Ptr[PFCB2],AX ;into the block
Mov AX, Offset Comm ;Make sure our command line is here
Mov Word Ptr[Clin],AX
; We must pass our sub-process an environment string. The segment
; of the current string is contained at CS:2C, so lets pass it that
Mov BX, 2cH
Mov AX,Word ptr[BX] ;get environ seg
Mov EnvStr,AX ;Save it
; The ShellData parameter block is now all filled in. Now we must
; allocate memory so that there is enough room to load SuperCom
; We are reserving 300 paragraphs for our program's use - alter
; this to suit. (See the DOS Tech Ref manual if unsure). 0FF
; paragraphs is about 16K, so work from that
Mov AH,4AH ;4A = Allocate memory
Mov BX,300H ;alocate this many paragraphs
Int 21H
Jc Error ;Whoops - allocate failed.
;Nothing more we can do
; All registers, even the stack, will be clobbered by the Exec
; Call, so we must save the Stack Segment and Stack Pointer
Mov SP_Save,SP
Mov SS_Save,SS
; Finally, the address of the filename string must be placed in DS:DX
Mov DX, offset Fname
; The address of ShellData must be plaved in BX
Mov BX, offset ShellData
; Now set up for the exec call
Mov AL,0 ;Function 0 = Exec
Mov AH,4BH ;4BH is the DOS function request #
Int 21H ;Do the EXEC
JC Error ;Exec failed - error
;
; OK, we are back and the only register we can be sure of is
; CS. Lets reload our Stack info
;
Mov SS,CS:SS_Save
Mov SP,CS:SP_Save
Clc ;Clear carry means successful load
;
; Now we can pop off our original registers
;
Pop_Regs:
Pop BP
Pop ES
Pop DS
Pop DI
Pop SI
Pop DX
Pop CX
Pop BX
Pop AX
Ret
Error: Stc ;Set carry means load failed
;System may be unhealthy
Jmp Pop_Regs
RET ;NEAR RETURN TO DOS
LOAD ENDP
START ENDP
CSEG ENDS
END ENTPT